using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;

using BlueGameComponent;

namespace AirForce
{
    class PauseScreen : MenuScreen
    {
        GameScreen gameScreen;

        public PauseScreen(GameScreen gameScreen)
            : base("Pause")
        {
            this.gameScreen = gameScreen;
            gameScreen.Pause = true;

            IsPopup = true;
            // Create our menu entries.
            TouchMenuEntry resumeGameMenuEntry = new TouchMenuEntry("Resume");
            TouchMenuEntry exitGameEntry = new TouchMenuEntry("Main Menu");

            // Hook up menu event handlers.
            resumeGameMenuEntry.Selected += ResumeSelected;
            exitGameEntry.Selected += ExitSelected;

            // Add entries to the menu.
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(exitGameEntry);

        }


        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.ExitScreen();
            }

            if (input.Gestures.Count > 0)
            {
                GestureSample sample = input.Gestures[0];
                if (sample.GestureType == GestureType.Tap)
                {
                    input.Gestures.Clear();
                }
            }
        }

        private void ResumeSelected(object sender, EventArgs e)
        {
            this.ExitScreen();
        }
        private void ExitSelected(object sender, EventArgs e)
        {
            ScreenManager.RemoveAllScreen();
            
        }
        public override void OnExit()
        {
            if ("Main Menu" == lastSelectedEnteryText)
            {
                ScreenManager.AddScreen(new MainMenuScreen(), null);
            }
            else
            {
                 gameScreen.Pause = false;
            }
        }
        public override void Draw(GameTime gameTime)
        {
            
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();
            Color color = Color.Black;
            DrawTransition(ScreenManager.blankTexture,
                new Rectangle(0, 0, ScreenManager.ViewPort.Width, ScreenManager.ViewPort.Height), color*0.3f);

            spriteBatch.End();
            
            base.Draw(gameTime);
        }
    }

}
